<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>12全屏滚动</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        body {
            overflow-x: hidden;
        }

        .box {
            height: 100vh;
            position: relative;
            overflow: hidden;
        }

        .wrap {
            position: absolute;
            top: 0;
        }

        .page {
            /* width: 100vw;
            height: 100vh; */
            color: white;
            text-align: center;
            /* line-height: 100vh; */
            font-size: 200px;
        }
    </style>
    <script src="../jquery-1.11.3/jquery.min.js"></script>
</head>

<body>
    <div class="box">
        <div class="wrap">
            <div class="page" style="background: red;">1</div>
            <div class="page" style="background: yellow;">2</div>
            <div class="page" style="background: blue;">3</div>
            <div class="page" style="background: green;">4</div>
            <div class="page" style="background: orange;">5</div>
        </div>
    </div>
</body>
<script>
    var oWrap = document.getElementsByClassName("wrap")[0];
    var aPages = document.getElementsByClassName("page");
    // console.log(window.innerWidth,window.innerHeight)
    for (var i = 0; i < aPages.length; i++) {
        aPages[i].style.height = window.innerHeight + "px";
        aPages[i].style.width = window.innerWidth + "px";
    }


    var index = 0;



    // 鼠标的滚轮事件
    // 火狐浏览器
    window.addEventListener("DOMMouseScroll", function (e) {
        console.log(e.detail);
        if (oWrap.offsetTop == -(window.innerHeight) * index) {
            if (e.detail > 0) {
                // 向下滚动
                index > 3 ? index = 4 : index++;
                oWrap.style.top = -(window.innerHeight) * index + "px";
                oWrap.style.transition = "all 1s ease";
            }
            if (e.detail < 0) {
                // 向上滚动
                index < 1 ? index = 0 : index--;
                oWrap.style.top = -(window.innerHeight) * index + "px";
                oWrap.style.transition = "all 1s ease";
            }
        } else {

        }

    })



    // 非火狐浏览器
    window.onmousewheel = function (ev) {
        // console.log(ev.wheelDelta);
        // console.log(oWrap.offsetTop == -(window.innerHeight) * index);
        ev = ev || window.event;
        // 根据top进行判断   top?
        if (oWrap.offsetTop == -(window.innerHeight) * index) {
            // on = true;
            if (ev.wheelDelta > 0) {
                // 页面向上滚动
                index < 1 ? index = 0 : index--;
                oWrap.style.top = -(window.innerHeight) * index + "px";
                oWrap.style.transition = "all 1s ease";
            }
            if (ev.wheelDelta < 0) {
                // 页面向下滚动
                index > 3 ? index = 4 : index++;
                oWrap.style.top = -(window.innerHeight) * index + "px";
                oWrap.style.transition = "all 1s ease";
            }
        } else {
            // return false;
        }
    }
</script>

</html>